package org.bedracket.pgeg.event;

import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.bedracket.pgeg.init.ModItems;
import org.bedracket.pgeg.util.Helpers;

@Mod.EventBusSubscriber
public class BlockEvents {

    @SubscribeEvent
    public static void addSeedDrop(BlockEvent.BreakEvent event) {
        var level = (Level) event.getLevel();
        var pos = event.getPos();
        var state = level.getBlockState(pos);
        if (state.is(Blocks.GRASS) || state.is(Blocks.TALL_GRASS)) {
            if (level.getRandom().nextInt(100) < 40) {
                Helpers.itemEntity(level, pos, ModItems.TOMATO.get().getDefaultInstance());
            }
        }
    }
}
